#!/bin/bash

# MCP Client Spring Boot Application Startup Script

echo "Starting MCP Client Application..."
echo "======================================"

# Check if Java is installed
if ! command -v java &> /dev/null; then
    echo "Error: Java is not installed or not in PATH"
    echo "Please install Java 17 or later"
    exit 1
fi

# Check Java version
JAVA_VERSION=$(java -version 2>&1 | awk -F '"' '/version/ {print $2}' | awk -F '.' '{print $1}')
if [ "$JAVA_VERSION" -lt 17 ]; then
    echo "Error: Java 17 or later is required"
    echo "Current Java version: $(java -version 2>&1 | head -n 1)"
    exit 1
fi

# Check if Maven is installed
if ! command -v mvn &> /dev/null; then
    echo "Error: Maven is not installed or not in PATH"
    echo "Please install Apache Maven"
    exit 1
fi

echo "Java version: $(java -version 2>&1 | head -n 1)"
echo "Maven version: $(mvn -version | head -n 1)"
echo ""

# Build and run the application
echo "Building and starting the application..."
echo "This may take a few minutes on first run..."
echo ""

# Run Maven Spring Boot
mvn spring-boot:run

echo ""
echo "Application stopped."